# -*- coding:utf-8 -*-
import json
from flask import request,Flask
import socket
import time
import pymysql
app = Flask(__name__)
# from socket_server import socketServer,sockets

addr = '139.196.189.46'
# addr = '127.0.0.1'

<<<<<<< HEAD
def recv_basic(the_socket):
    data = the_socket.recv(20480)    
    return data


@app.route('/api/customerlocked/getlockedcustomers',methods=["POST"])
def getCustomers():
    condition = request.values.get('condition','')
    data = [{'url':'/api/customerlocked/getlockedcustomers'},{'condition':condition}]
=======
def socketRequest(data):
>>>>>>> 6a3b87d916684587bd6f1ca58d5d540b906493e9
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect((addr,8080))
    data = json.dumps(data)
    data = data.encode('utf-8')
    true = True
    s.send(data)
    time.sleep(0.5)
    data = recv_basic(s)
    app.logger.debug(data)
    return data

    

@app.route('/api/customerlocked/getlockedcustomers',methods=["POST"])
def getCustomers():
    condition = request.values.get('condition','')
    data = [{'url':'/api/customerlocked/getlockedcustomers'},{'condition':condition}]
    res = socketRequest(data)
    return res


@app.route('/api/customerlocked/updatecustomerstatus',methods=['POST'])
def updateCustomer():
    fcsid = request.values.get('fcsid','')
    status = request.values.get('status',0)
    data = [{'url':'/api/customerlocked/updatecustomerstatus'},{'fcsid':fcsid,'status':status}]
    res = socketRequest(data)
    return res

@app.route('/api/user/login',methods=['POST'])
def login():
    loginname = request.values.get('loginname','')
    passowrd = request.values.get('password','')
    data= [{'url':'/api/user/login'},{'loginname':loginname,'password':passowrd}]
    res = socketRequest(data)
    return res

if __name__ == '__main__':
    app.run('0.0.0.0', debug=True, port=443, ssl_context=("cert/cert.pem","cert/key.pem"))
